
/**
 * The set height command, takes a new height, which is used to set
 * height after execute is called. The set height command object
 * is defined by the new height and the model, and therefore
 * none of the attributes can be reset after the command has been created
 * @author Sophia Soohoo
 *
 */
public class SetHeight extends BrickCommand {

    /**the new height of the brick model*/
    private double newHeight = 0;
    
    /**
     * The constructor for set height command. Takes the current
     * model and the new height used by execute
     * @param model     the brick model
     * @param newHeight the new height of the model
     */
    public SetHeight(BrickModel model, double newHeight) {
        super.setModel(model);
        super.setMemento(model.makeMemento());
        this.newHeight = newHeight;
    }

    /**
     * Execute the command
     * @throw CommandException
     * @catch BrickException and pass to CommandException
     */
    @Override
    public void execute() throws CommandException {   
    	try {
			super.getModel().setHeight(newHeight);
		} catch (BrickException e) {
			throw new CommandException(e.getMessage());
		}
    }
    
    /**
     * @return the newHeight
     */
    public double getNewHeight() {
        return newHeight;
    }

    /* (non-Javadoc)
     * @see Command#toString()
     */
    @Override
    public String toString() {
        return "new height: " + newHeight;
    }
}
